//
//  NSColorView.swift
//  SFDevFly
//
//  Created by shen on 2023/9/27.
//

import Cocoa

class NSColorView: NSView {
    var borderWidth: CGFloat = 1 { didSet { setNeedsDisplay(bounds) } }
    var borderColor: NSColor? { didSet { setNeedsDisplay(bounds) } }
    var backgroundColor: NSColor? { didSet { setNeedsDisplay(bounds) } }

    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)

        if let backgroundColor = backgroundColor {
            backgroundColor.setFill()
            dirtyRect.fill()
        }

        if let borderColor = borderColor {
            borderColor.setStroke()
            let path = NSBezierPath(rect: dirtyRect)
            path.lineWidth = borderWidth
            path.stroke()
        }
    }
}
